package com.matt.controller.web;

import com.matt.domain.news.SystemNotification;

import com.matt.commons.model.StatusResponse;
import com.matt.foundation.query.NewsQuery;
import com.matt.service.SystemNotificationService;

import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * *******************************
 * Created by lch.
 * form com.matt
 * on 2018/11/28
 * *******************************
 */
@RestController
@RequestMapping(value = "/web/news")
public class WebNewsController {

    @Autowired
    private SystemNotificationService systemNotificationService;

    //分页
    @ApiOperation(value = "新闻分页",httpMethod = "POST")
    @RequestMapping(value = "/page")
    public StatusResponse page(NewsQuery query) {
        Page<SystemNotification> page = systemNotificationService.page(query);
        return StatusResponse.success(page);
    }

    //详情
    @ApiOperation(value = "新闻详情",httpMethod = "POST")
    @RequestMapping(value = "/detail")
    public StatusResponse detail(String id) {
        return StatusResponse.success(systemNotificationService.detail(id));
    }

    //通知新曾
    @ApiOperation(value = "新闻新增",httpMethod = "POST")
    @RequestMapping(value = "/add")
    public StatusResponse add(String name, String date, String text, String json) {
        return StatusResponse.success(systemNotificationService.add(name, date, text, json));
    }

    //通知修改
    @ApiOperation(value = "新闻修改",httpMethod = "POST")
    @RequestMapping(value = "/update")
    public StatusResponse update(String id, String name, String date, String text, String json) {
        return StatusResponse.success(systemNotificationService.update(id, name, date, text, json));
    }

    //删除
    @ApiOperation(value = "新闻删除",httpMethod = "POST")
    @RequestMapping(value = "/delete")
    public StatusResponse delete(String id) {
        return StatusResponse.success(systemNotificationService.delete(id));
    }

    //查询最近的通告信息
    @ApiOperation(value = "新闻",httpMethod = "POST")
    @RequestMapping(value = "/news")
    public StatusResponse recentlyNews() {
        return StatusResponse.success(systemNotificationService.recentlyNews());
    }
}
